#include "stdafx.h"
#include "GResourceUser.h"


GResourceUser::GResourceUser(ACE_Process_Mutex &mutex) : gmutex_(mutex)
{
}


void GResourceUser::run(void)
{
	ACE_TRACE("GResourceUser::run");

	int count = 0;
	while (count++ < 10)
	{
		int result = this->gmutex_.acquire();
		ACE_TEST_ASSERT(result == 0);

		ACE_DEBUG((LM_DEBUG,
			ACE_TEXT("(%P| %t) has the mutex\n")));

		// Access Global resource
		ACE_OS::sleep(1);

		result = this->gmutex_.release();
		ACE_TEST_ASSERT(result == 0);
		ACE_OS::sleep(1);     // Give other process a chance.
	}
}
